package org.example.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@Slf4j
public class GetCookieController {
    @ResponseBody
    @RequestMapping("/cookie")
    public Object cookie(@CookieValue String abc){
        log.debug("cookie: abc={}",abc);
        return null;
    }


    //这里是请求
    @RequestMapping("/request")
    @ResponseBody
    public Object request(HttpServletRequest req,
                          HttpServletResponse res
    ){//如果想要获取IP或者端口号那些就要通过其他API来获取了。
        log.debug("method={},url={}",req.getMethod(),req.getRequestURI());
        log.debug("response = {}",res);
        return null;
    }

    @RequestMapping("/session")
    @ResponseBody
    public Object session(HttpSession session){
        log.debug("session = {}",session);
        return null;
    }

    @RequestMapping("/login")
    @ResponseBody
    public Object login(HttpServletRequest req,
                        String username,
                        String password){
        //模拟验证登陆成功
        if("xxx".equals(username) && "456".equals(password)){
            HttpSession session = req.getSession();
            session.setAttribute("username",username);
        }
        return null;
    }

    @RequestMapping("/check")
    @ResponseBody
    public Object check(@SessionAttribute String username) {
        log.debug("username={}",username);
        return null;
    }
}
